Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: acknowledgement is not aligned with underlying_app_success #1633

Merged
merged 5 commits into from
Oct 14, 2024

Conversation

mmsqe
Copy link
Collaborator

@mmsqe mmsqe commented Oct 9, 2024

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

when packet does not succeed

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Summary by CodeRabbit

  • New Features

    • Enhanced support for IBC channel upgrade methods.
    • Improved handling of interchain account (ICA) test parameters for more flexible message submissions.
  • Improvements

    • Adjusted parallelism settings for block-stm to optimize performance.
    • Updated ethermint to streamline API calls and eliminate unnecessary results.
    • Enhanced acknowledgment processing to account for failure states in transaction handling.
  • Bug Fixes

    • Resolved issues with multisig account handling and transaction validation.
    • Fixed query logic for address-by-account-number.
  • Documentation

    • Updated changelog to reflect detailed versioning and significant changes across releases.

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 36.30%. Comparing base (18c337a) to head (cdec1dd).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
x/cronos/keeper/keeper.go 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1633       +/-   ##
===========================================
+ Coverage   17.87%   36.30%   +18.42%     
===========================================
  Files          72      123       +51     
  Lines        5168     9717     +4549     
===========================================
+ Hits          924     3528     +2604     
- Misses       4121     5775     +1654     
- Partials      123      414      +291     
Files with missing lines Coverage Δ
x/cronos/keeper/keeper.go 62.73% <0.00%> (+55.18%) ⬆️

... and 68 files with indirect coverage changes

CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: mmsqe <mavis@crypto.com>
@mmsqe mmsqe changed the title Problem: no easy way to detect error ack packet Problem: acknowledgement is not aligned with underlying_app_success Oct 9, 2024
@mmsqe mmsqe marked this pull request as ready for review October 9, 2024 09:21
@mmsqe mmsqe requested a review from a team as a code owner October 9, 2024 09:21
@mmsqe mmsqe requested review from yihuang and thomas-nguy and removed request for a team October 9, 2024 09:21
Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

Walkthrough

The changes in this pull request primarily involve updates to the CHANGELOG.md, enhancements to interchain account tests in integration_tests/test_ica_precompile.py, and modifications to the acknowledgment handling within the Keeper struct in x/cronos/keeper/keeper.go. The CHANGELOG.md reflects breaking changes, improvements, and bug fixes across multiple software versions. The test file enhancements improve transaction status checks and message submission handling. The Keeper struct changes introduce a conditional check for acknowledgment processing, ensuring robust handling of application responses.

Changes

File Path Change Summary
CHANGELOG.md Updated to reflect breaking changes, improvements, bug fixes, and versioning details.
integration_tests/test_ica_precompile.py Enhanced ICA tests with new parameters and assertions for message submission and transaction status.
x/cronos/keeper/keeper.go Modified IBCOnAcknowledgementPacketCallback to include a check for unsuccessful acknowledgments.

Possibly related PRs

Suggested reviewers

  • calvinaco
  • yihuang
  • thomas-nguy

🐰 "In the changelog, updates abound,
With fixes and features, joy is found.
From IBC's channels to tests that excel,
Our code hops forward, all is well!
So let’s celebrate, with a cheer and a dance,
For each little change, gives progress a chance!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
x/cronos/keeper/keeper.go (2)

320-322: Approve changes with a minor suggestion for clarity

The new conditional check for ack.UnderlyingAppSuccess is a good addition. It ensures that failed underlying application responses are properly handled, improving the robustness of the acknowledgment processing logic.

Consider adding a comment explaining the purpose of this check for better code readability:

+  // Handle cases where the underlying application was unsuccessful
   if !ack.UnderlyingAppSuccess {
     return k.onPacketResult(ctx, packet, false, relayer, contractAddress, packetSenderAddress)
   }

320-322: Summary of changes and final considerations

The changes in this file are focused on improving the handling of unsuccessful underlying app responses in the IBCOnAcknowledgementPacketCallback function. This directly addresses the PR objective of aligning acknowledgment with underlying app success.

Consider the following final points:

  1. Ensure that this change is reflected in the CHANGELOG.md as it modifies the behavior of IBC packet handling.
  2. Update any relevant documentation that describes the IBC acknowledgment process.
  3. Consider adding or updating unit tests to cover both successful and unsuccessful underlying app scenarios.

As this change affects the IBC packet handling process, which is a critical part of the inter-blockchain communication, it's important to thoroughly test this change in a staging environment that simulates various IBC scenarios before merging to production.

integration_tests/test_ica_precompile.py (2)

321-322: Remove redundant variable assignments

At lines 321-322, balance and start are reassigned. If these variables have not changed since their last assignment, reassigning them is unnecessary and could confuse readers.

Consider removing the redundant assignments:

-    balance = funds_ica(cli_host, ica_address, signer=signer)
-    start = w3.eth.get_block_number()

323-333: Improve readability of submit_msgs function call arguments

The arguments passed to submit_msgs from lines 323 to 333 can be formatted for better readability and maintainability.

Apply this diff to reformat the arguments:

 str, diff = submit_msgs(
     ibc,
     tcontract.functions.callSubmitMsgs,
     data,
     ica_address,
     False,
     expected_seq,
     contract.events.SubmitMsgsResult,
     channel_id,
     signer=signer,
 )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fb902d2 and 2759bfd.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • integration_tests/test_ica_precompile.py (2 hunks)
  • x/cronos/keeper/keeper.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
x/cronos/keeper/keeper.go (1)

320-322: Verify the impact of this change across the codebase

The new condition for handling unsuccessful underlying app responses addresses the PR objective. To ensure this change doesn't have unintended consequences, it's important to verify its impact across the codebase.

Please run the following script to check for any other occurrences of UnderlyingAppSuccess and ensure they are handled consistently:

This will help ensure that the change is consistent with other parts of the codebase and that appropriate test cases exist.

CHANGELOG.md (1)

27-27: LGTM: New bug fix added to UNRELEASED section

The new line correctly documents a bug fix related to acknowledgement alignment with underlying app success when the acknowledgement packet does not succeed. This is properly linked to the corresponding pull request (#1633).

integration_tests/test_ica_precompile.py (3)

Line range hint 308-337: Confirm that all function calls are updated with the correct parameters

Throughout the changes from lines 308 to 337, ensure that all calls to submit_msgs and related functions use the correct and updated parameters, especially after any refactoring.

Run the following script to check for parameter usage:

#!/bin/bash
# Description: Find all calls to `submit_msgs` and list their parameters.

# Test: Extract `submit_msgs` calls and display the parameters.
rg --type python 'submit_msgs\(' -A 10

317-318: ⚠️ Potential issue

Correct indentation and ensure proper assertion placement

Lines 317-318 contain assertion statements that are not indented properly. This could lead to syntax errors or logical issues in the test execution.

Apply this diff to fix the indentation:

-    assert expected_seq == last_seq
-    assert status == Status.FAIL
+        assert expected_seq == last_seq
+        assert status == Status.FAIL

Likely invalid or redundant comment.


308-308: Clarify need_wait=False parameter

In line 308, when calling submit_msgs, the parameter need_wait is set to False. This means the function will not wait for the transaction confirmation, which might lead to race conditions or flaky tests if subsequent code depends on the transaction's completion. Ensure that this is intentional and that the test accounts for the asynchronous nature of the call.

Consider verifying the necessity of need_wait=False:

✅ Verification successful

Clarify need_wait=False Parameter

After analyzing the codebase, there are no subsequent assertions or operations that depend on the transaction's confirmation following submit_msgs calls with need_wait=False. This setup appears intentional and the tests account for the asynchronous nature of the call.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if any other parts of the test depend on the transaction confirmation.

# Test: Search for usage of variables that might be affected.
rg --type python 'last_seq|status|balance' -A 5

Length of output: 165


Script:

#!/bin/bash
# Description: Verify if other parts of the test depend on the transaction confirmation by searching for relevant variables.

# Corrected rg command with proper file type and syntax
rg --type py 'submit_msgs\(' -A 10

Length of output: 9017


Script:

#!/bin/bash
# Description: Identify if there are any assertions or operations following submit_msgs calls that depend on transaction confirmation.

# Search for submit_msgs calls with need_wait=False and check the next few lines for assertions or state-dependent operations.
rg --type py 'submit_msgs\([^)]*need_wait=False[^)]*\)' -A 10

Length of output: 63

integration_tests/test_ica_precompile.py Show resolved Hide resolved
integration_tests/test_ica_precompile.py Show resolved Hide resolved
@mmsqe mmsqe enabled auto-merge October 14, 2024 07:44
@mmsqe mmsqe added this pull request to the merge queue Oct 14, 2024
x/cronos/keeper/keeper.go Outdated Show resolved Hide resolved
@yihuang yihuang removed this pull request from the merge queue due to a manual request Oct 14, 2024
Co-authored-by: mmsqe <mavis@crypto.com>
Signed-off-by: yihuang <huang@crypto.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2759bfd and cdec1dd.

📒 Files selected for processing (2)
  • integration_tests/test_ica_precompile.py (2 hunks)
  • x/cronos/keeper/keeper.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
x/cronos/keeper/keeper.go

[warning] 320-321: x/cronos/keeper/keeper.go#L320-L321
Added lines #L320 - L321 were not covered by tests

🔇 Additional comments (4)
integration_tests/test_ica_precompile.py (4)

309-309: LGTM: Improved flexibility in message submission

The addition of need_wait=False allows for more flexible handling of message submission without waiting for confirmation. This change is consistent with the updated submit_msgs function signature and provides better control over the test flow.


318-320: LGTM: Improved error handling and log verification

The addition of the assertion assert status == Status.FAIL and the wait_for_packet_log function call significantly improves the test's robustness. These changes ensure that the test properly verifies the failure status and waits for the corresponding log, addressing the previous concern about error handling for unexpected statuses.


338-338: LGTM: Improved sequence verification

The addition of assert expected_seq == last_seq is a valuable improvement to the test. This assertion ensures that the expected sequence number matches the last sequence number returned by the contract, verifying the correct sequencing of operations in the ICA functionality.


321-338: 🛠️ Refactor suggestion

Consider refactoring repetitive code patterns

While the added code successfully performs the necessary steps for testing ICA functionality, there are still repetitive patterns that could benefit from refactoring. Consider creating a helper function to encapsulate the common operations of funding, submitting messages, and verifying status. This would improve code maintainability and readability.

Example refactoring:

def perform_ica_operation(ibc, tcontract, ica_address, expected_seq, signer):
    balance = funds_ica(ibc.chainmain.cosmos_cli(), ica_address, signer=signer)
    start = ibc.cronos.w3.eth.get_block_number()
    str, diff = submit_msgs(
        ibc,
        tcontract.functions.callSubmitMsgs,
        {"from": ADDRS[signer], "gas": 500000},
        ica_address,
        False,
        expected_seq,
        tcontract.events.SubmitMsgsResult,
        get_next_channel(ibc.cronos.cosmos_cli(), connid),
        signer=signer,
    )
    last_seq = tcontract.caller.getLastSeq()
    wait_for_status_change(tcontract, channel_id, last_seq)
    status = tcontract.caller.getStatus(channel_id, last_seq)
    assert expected_seq == last_seq
    assert status == Status.SUCCESS
    wait_for_packet_log(start, tcontract.events.OnPacketResult, channel_id, last_seq, status)
    return balance - diff

This refactoring would make the test more maintainable and easier to read.

x/cronos/keeper/keeper.go Show resolved Hide resolved
@yihuang yihuang added this pull request to the merge queue Oct 14, 2024
Merged via the queue into crypto-org-chain:main with commit 8425423 Oct 14, 2024
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants